package com.databasedesign.advice;

import com.databasedesign.exception.ResultException;
import com.databasedesign.pojo.dto.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class ExceptionHandler {
    @org.springframework.web.bind.annotation.ExceptionHandler(ResultException.class)
    public Result handleGseinException(ResultException e) {
        log.error(e.getMessage(), e);
        return new Result(e.getCode(), e.getMessage());
    }

    @org.springframework.web.bind.annotation.ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {
        log.error(e.getMessage(), e);
        return new Result(e.getMessage());
    }
}
